<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="选课学生学号" prop="selectid">
    <el-input v-model="ruleForm.selectid"></el-input>
    </el-form-item>
  <el-form-item label="选课学生姓名" prop="selectname">
    <el-input v-model="ruleForm.selectname"></el-input>
  </el-form-item>
  <el-form-item label="被选课程课程号" prop="courseid">
    <el-input v-model="ruleForm.courseid"></el-input>
  </el-form-item>
  <el-form-item label="被选课程课程名" prop="coursename">
    <el-input v-model="ruleForm.coursename"></el-input>
  </el-form-item>
  <el-form-item label="选课时间" prop="selectedtime">
    <el-input v-model="ruleForm.selectedtime"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
    <el-button type="info" @click="back">返回</el-button>
  </el-form-item>
</el-form>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      ruleForm: {
        selectid: '',
        selectname: '',
        courseid: '',
        coursename: '',
        selectedtime: ''
      },
      rules: {
        selectid: [
          { required: true, message: '选课学生学号不能为空', trigger: 'blur' }
        ],
        selectname: [
          { required: true, message: '选课学生姓名不能为空', trigger: 'blur' }
        ],
        courseid: [
          { required: true, message: '被选课程课程号不能为空', trigger: 'blur' }
        ],
        coursename: [
          { required: true, message: '被选课程课程名不能为空', trigger: 'blur' }
        ],
        selectedtime: [
          { required: true, message: '选课时间不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post('http://localhost:8082/StudentManagement-Web/selectcourse/save.json', this.ruleForm).then(function (resp) { alert('success') })
        } else {
          console.log('失败!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    back () {
      this.$router.replace('/SelectCourseMain')
    }
  }
}
</script>
